package com.bawei.module_mine.applyfor

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.base.state.UILoader
import com.bawei.lib_common.base.state.UIState
import com.bawei.lib_common.base.utils.LoggerUtils
import com.bawei.lib_common.base.utils.ToastUtils
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.module_mine.R
import com.bawei.module_mine.adapter.ApplyForAdapter
import com.bawei.module_mine.adapter.MineAdapter
import com.bawei.module_mine.databinding.ActivityApplyForBinding
import com.bawei.module_mine.databinding.LayoutApplyforContentBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
@Route(path = Router.Ui.ApplyForActivity)
class ApplyForActivity : BaseActivity<ApplyForViewModel, ActivityApplyForBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_apply_for
    override val mViewModel: ApplyForViewModel by viewModels()
    private lateinit var mContentBinding: LayoutApplyforContentBinding
    private val mApplyForAdapter: ApplyForAdapter by lazy {
        ApplyForAdapter()
    }

    override fun initView() {
        initUILoader()
        initAdapter()
    }

    override fun initListener() {
        mViewModel.parkingEvent.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    mApplyForAdapter.setCarData(mViewModel.parkingList)
                }
            }
        }
        mViewModel.visitEvent.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    mApplyForAdapter.setVisitData(mViewModel.visitList)
                }
            }
        }
        mViewModel.repairEvent.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    mApplyForAdapter.setRepairData(mViewModel.repairList)
                }
            }
        }
        mViewModel.inspectionEvent.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    mApplyForAdapter.setInspectionData(mViewModel.inspectionList)
                }
            }
        }
    }

    override fun initData() {
        mViewModel.getVisitList()
        mViewModel.getRepairList()
        mViewModel.getInspectionList()
        mViewModel.getsParkingList()
        mBinding.appbarHeard.apply {
            imageView2.setOnClickListener {
                finish()
            }
        }
    }
    private fun initUILoader() {
        mContentBinding = DataBindingUtil.inflate(
            LayoutInflater.from(this),
            R.layout.layout_applyfor_content,
            null,
            false
        )
        mBinding.layoutContent.addView(mContentBinding.root)
    }
    private fun initAdapter() {
        mApplyForAdapter.setupLayoutManager(mContentBinding.applyforRec)
        mContentBinding.applyforRec.adapter = mApplyForAdapter
    }

}